package cn.text.ico;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import net.sf.image4j.use.Image4j;

public class PicDown {
    public static int count = 0;

    public static void Down(String ulr, String name) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        try {
            CloseableHttpResponse httpResponse1 = httpClient.execute(new HttpGet(ulr));
            HttpEntity entity1 = httpResponse1.getEntity();
            java.io.InputStream inputStream = entity1.getContent();
            FileUtils.copyToFile(inputStream,
                    new File(WelcomeInterface.path.getText().replace('\\', '/') + "\\" + name + ".png"));
            Image4j.ConvertIamgeToICO(WelcomeInterface.path.getText().replace('\\', '/') + "\\" + name + ".png",
                    WelcomeInterface.path.getText().replace('\\', '/') + "\\ico\\" + name + ".ico"); // 将下载下来的png文件转成ico
            WelcomeInterface.log.append("下载图标：" + name + ".ico" + "\n\r");
            count++;
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            WelcomeInterface.log.append("下载失败，没有该图标！");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            WelcomeInterface.log.append("请检查网络！");
        }
    }
}
